<template>
  <div>
    <h2>登录</h2>账号
    <input type="text" v-model="username" />
    密码
    <input type="text" v-model="password" />
    <button @click="sub">登录</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      username: "",
      password: ""
    };
  },
  methods:{
      sub:function(){
        //
        this.axios({
            url:'http://127.0.0.1:8000/app03/login/',
            method:'post',
            data:{"username":this.username,"password":this.password}
        }).then(res=>{
            if(res.data.code==1000){
                // 1
                localStorage.setItem('auth',res.data.data.auth);
                localStorage.setItem('uid',res.data.data.uid);
                // 2
                this.$router.push('/goods')
            }else{
                alert(res.data.msg);
            }
        })
      }
  }
};
</script>

<style>
</style>